package cn.source.system.controller;

import cn.source.common.annotation.Log;
import cn.source.common.core.controller.BaseController;
import cn.source.common.core.domain.AjaxResult;
import cn.source.common.core.page.TableDataInfo;
import cn.source.common.enums.BusinessType;
import cn.source.common.utils.poi.ExcelUtil;
import cn.source.system.domain.DeyuVersion;
import cn.source.system.service.IDeyuVersionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 版本包信息Controller
 *
 * @author deyucare.com
 * @date 2025-02-20
 */
@RestController
@RequestMapping("/deyu/version")
public class DeyuVersionController extends BaseController
{
    @Autowired
    private IDeyuVersionService deyuVersionService;

    /**
     * 查询版本包信息列表
     */
    @PreAuthorize("@ss.hasPermi('deyu:version:list')")
    @GetMapping("/list")
    public TableDataInfo list(DeyuVersion deyuVersion)
    {
        startPage();
        List<DeyuVersion> list = deyuVersionService.selectDeyuVersionList(deyuVersion);
        return getDataTable(list);
    }

    /**
     * 获取版本包信息详细信息
     */
    @GetMapping
    public AjaxResult getInfo()
    {
        return AjaxResult.success(deyuVersionService.selectDeyuVersionByRecent());
    }

    /**
     * 新增版本包信息
     */
    @PreAuthorize("@ss.hasPermi('deyu:version:add')")
    @Log(title = "版本包信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DeyuVersion deyuVersion)
    {
        return toAjax(deyuVersionService.insertDeyuVersion(deyuVersion));
    }

    /**
     * 修改版本包信息
     */
    @PreAuthorize("@ss.hasPermi('deyu:version:edit')")
    @Log(title = "版本包信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DeyuVersion deyuVersion)
    {
        return toAjax(deyuVersionService.updateDeyuVersion(deyuVersion));
    }

    /**
     * 删除版本包信息
     */
    @PreAuthorize("@ss.hasPermi('deyu:version:remove')")
    @Log(title = "版本包信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(deyuVersionService.deleteDeyuVersionByIds(ids));
    }

    /**
     * 导出版本包信息列表
     */
    @PreAuthorize("@ss.hasPermi('deyu:version:export')")
    @Log(title = "版本包信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DeyuVersion deyuVersion)
    {
        List<DeyuVersion> list = deyuVersionService.selectDeyuVersionList(deyuVersion);
        ExcelUtil<DeyuVersion> util = new ExcelUtil<DeyuVersion>(DeyuVersion.class);
        util.exportExcel(response, list, "版本包信息数据");
    }
}
